﻿Chenxin.UI.PublicHouseManage = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: 'service/publicHouse.ashx',
    createGrid: function() {
        return new Chenxin.UI.Pagination({
            actionUrl: this.actionUrl + '?op=getlist',
            id: 'publichouse',
            renderTo: 'publichouse_table'

        });
    },
    cancle: function() {

    },
    initEvent: function() {
        var _this = this;
        $('.insertHouseData').live('click', function() {
            _this.showpublichouse();
        });
        $('.allothouseMgr').live('click', function() {
            _this.showupload();
        });
        $('.a_del_choose').live('click', function() {
            _this.deleteList();
        });
        $('.a_transformed').live('click', function() {
            if (!confirm('确定要转换该条记录吗？')) {
                return false;
            }
        });

        $('.a_already_transformed').live('click', function() {
            alert('该条房源已经转换过！');
            return false;
        });

        $('.check_all').live('click', function() {
            $(':checkbox').each(function() {
                if (this.checked) {
                    this.checked = false;
                } else {
                    this.checked = true;
                }
            });
            return false;
        });

    },
    deleteList: function() {//删除操作
        var _this = this;
        var id = "";
        $(':checkbox:checked').each(function() {
            if (this.name) {
                if (id == '') {
                    id += this.value;
                } else {
                    id += "," + this.value;
                }
            }
        });
        if (!id) {
            alert('请选择一条记录！');
            return;
        }
        if (confirm('确定要删除选中记录吗？')) {
            Chenxin.ajax({
                type: "post",
                dataType: "json",
                url: this.actionUrl,
                data: { op: 'deletelist', modelid: id },
                onSuccess: function(data, msg) {
                    alert(msg);
                    if (_this.grid) {
                        _this.grid.reload();
                    }
                    if (this.afterDelSucc) {
                        _this.afterDelSucc.call(_this, data, msg);
                    }
                }
            });
        }
    },
    createSearch: function() {
        return new Chenxin.UI.PublicHouseManageSearch({
            scope: this
        });
    },
    initComponent: function() {
        Chenxin.UI.PublicHouseManage.superclass.initComponent.call(this);
    },
    showpublichouse: function() {
        if (!this.publichouse) {
            this.publichouse = new Chenxin.UI.PublicHouse({
                currentId: this.currentId,
                scope: this,
                afterGetFormJson: function(json) {
                    if (this.publichouse.op == 'add') {
                        if (this.publichouse.currentCommunityInfo)
                            json.CommunityId = this.publichouse.currentCommunityInfo.CommunityId;
                    }
                }
            });
        }
        this.publichouse.setTitle('资料盘录入');
        this.publichouse.show();
        this.publichouse.currentId = this.currentId;
    },
    showupload: function() {
        if (!this.uploadwin) {
            this.uploadwin = new Chenxin.UI.UploadWin({
                currentId: this.currentId,
                scope: this
            });
        }
        this.uploadwin.setTitle('导入楼盘');
        this.uploadwin.show('fileupload');
        this.uploadwin.currentId = this.currentId;
    }
});


/**
*查询面板
*/
Chenxin.UI.PublicHouseManageSearch=Chenxin.extend(Chenxin.UI.SearchCommon,{
    id: 'publichouse_search',
	initEvent:function(){
		var _this=this;
		$('#btn_search').click(function(){
			_this.scope.reloadGrid();
        });
        //小区自动填充
        $('#txtHousing').autocomplete({
            deferRequestBy: 5,
            serviceUrl: 'service/housemgr.ashx?op=loadcommunity'
        });
	},
	createComboList: function() {
	    var region = new Chenxin.UI.ParameterCombo({
	        name: 'region',
	        containerId: '#region',
	        key: 'System.Region',
	        tbxWidth: 45,
	        inModelType: 'txt',
	        onSelected: function() {
	            if (this.getValue() == this.defVal) {
	                block.clearItems();
	            } else {
	                block.param.subkey = this.getValue();
	                block.reload();
	            }
	        }
	    });
	    var block = new Chenxin.UI.ParameterCombo({
	        containerId: '#block',
	        key: 'System.Block',
	        tbxWidth: 45,
	        colWidth: 90,
	        inModelType: 'txt',
	        autoLoad: false
	    });
	    var houseuse = new Chenxin.UI.ParameterCombo({
	        containerId: '#houseuse',
	        key: 'House.Use',
	        autoLoad: true,
	        tbxWidth: 45,
	        inModelType: 'txt',
	        paramType: 'text'
	    });
	    var buildingtype = new Chenxin.UI.ParameterCombo({
	        containerId: '#buildingtype',
	        key: 'Building.Type',
	        autoLoad: true,
	        tbxWidth: 45,
	        inModelType: 'txt',
	        paramType: 'text'
	    });
	    
	    var combl = new Chenxin.UI.StructComboList();
	    var structs = combl.comboList;
	    structs.push(region);
	    structs.push(block);
	    structs.push(houseuse);
	    structs.push(buildingtype);
	    return structs;
	},
	initComponent:function(){
		Chenxin.UI.PublicHouseManageSearch.superclass.initComponent.call(this);
	}
});


$(document).ready(function(){
    var Mgr = new Chenxin.UI.PublicHouseManage();
});





